var App = require('app');

App.UserSignupController = Em.ObjectController.extend({
	signup: function(form) {
		var me = this;
		var p = $('#signupForm').validate({
			rules: {
	          confirmPassword: { 
	                equalTo: "#inputPassword"
	          }
			}
		}).form();
		if (!p) return;
		
		$("#signupForm").ajaxSubmit(function(json) {
			if (json.success) {
				if (Util.isNotEmpty(json.token)) {
					$.cookie(Vari.TokenName, json.token);
				} else {
					$.removeCookie(Vari.TokenName);
				}
				Vari.UserEmail = json.email;
				me.transitionToRoute("apps");
			} else {
				$.removeCookie(Vari.TokenName);
				new $.Zebra_Dialog('<strong>Email exist!</strong>!', {
				    'buttons':  false,
				    'modal': false,
				    'position': [],
				    'auto_close': 1000
				});
			}
	    });
	    return false;
	}
});